<template>
	<a-form-item
	:class="[hasError ? 'hhg-form-item-has-error' : '']"
	:label="labelName"
	:name="name"
	:rules="rules">
		<div class="uploadList">
			<div class="theme-txt">
				<a-radio-group v-model:value="radioValue" class="radioClass">
					<a-radio v-for="item in radioLists" :key="item.value" :disabled="isRead" :value="item.value" v-bind="attrs" @change="radioChange(item)">
						<div :class="[radioValue === 'Transfer' ? 'radiodiv' : '']" >
							<a-tooltip placement="top" overlayClassName="tableImageToolTips">
								<template #title>
									<div v-html="item.tip"></div>
								</template>
									<span>{{ item.label }}</span>
							</a-tooltip>
							<div class="radioinput"  v-if="radioValue === 'Transfer' && item.lang === 'member'">
								<HhgInputMember class="hhg-radioInputMember" @fuzzySearch="fuzzySearchMember" @onClickPopup="onClickPopup" v-model:value="memberValue" @selectedMember="selectedSingleMember" @clearMebmer="clearApplyMebmer" @selectLettersSingle="selectLettersSingle" v-bind="attrs" :config="{
									readonly: true,
									memberList: radioMemberList,
									title: '选择成员',
									subTitle: '待选人员（您可以通过搜索查询人员）',
									multiple,
									type: 1//type=1-返回人员姓名+人员code  2-返回人员姓名+人员code + 返回单个数据流,multiple-false是单选true是多选
								}"/>
							</div>
							<div class="radioselect" v-if="radioValue === 'MoreApprove' && item.lang === 'mixedMember'">
								<HhgMixedSelectionMember @removeFn="removeFn" @SwitchTab="SwitchTab" @selectLetters="selectLetters" @fuzzySearch="fuzzySearch" @selectedMember="selectedMember" @clearMixedMebmer="clearMixedMebmer" @onClickPopupRadioMixed="onClickPopupRadioMixed" v-model:mixMember="mixMember" :list="hhgMixedList" :config="{
									type: 2, options, multiple: true, mixMember, displayList//type=1-返回人员姓名+人员code  2-返回人员姓名+人员code + 返回单个数据流,multiple-false是单选true是多选
								}"/>
							</div>
						</div>
					</a-radio>
				</a-radio-group>
			</div>
		</div>
	</a-form-item>
</template>
<script setup>
import { onMounted, ref, defineProps, useAttrs, defineAsyncComponent, defineEmits, watch } from 'vue'
import _ from 'lodash'
const HhgMixedSelectionMember = defineAsyncComponent(() =>
  import('./hhg-mixedSelectionMember')
)
const HhgInputMember = defineAsyncComponent(() =>
	import('./hhg-inputSingleMember')
)
//父组件传过来的值
const props = defineProps({
  config: {
	type: Object,
	default: ()=> {}
  },
  list: Array,
  mixedList: Array,
  radioList: Array
})
const radioMemberList = ref([])
const radioLists = ref([])
const displayList = ref([])
watch(() => props.radioList, (val) => {
  if (val) {
	radioLists.value = val
  }
}, { immediate: true }, { deep: true })
watch(() => props.list, (val) => {
  if (val) {
	radioMemberList.value = val
  }
}, { immediate: true }, { deep: true })
const hhgMixedList = ref([])
watch(() => props.mixedList, (val) => {
  if (val) {
	hhgMixedList.value = val
  }
}, { immediate: true }, { deep: true })
watch(() => props.config, (val) => {
	if (!_.isEmpty(val.displayList)) {
		displayList.value = val.displayList
	}
}, { immediate: true }, { deep: true })

//组件属性穿透
const attrs = useAttrs()

const labelName = ref(props.config.labelName)
const name = ref(props.config.name)
const rules = ref(props.config.rules)
const isRead = ref(null)
const multiple = ref(props.config.multiple)
const options = ref(props.config.options)
const hasError = ref(props.config.hasError ? props.config.hasError : false)
watch(() => props.config.isRead, (val) => {
  if (val) {
	isRead.value = val
  }
}, { immediate: true }, { deep: true })

//单选框
const radioValue = ref('')
const emit = defineEmits(['fuzzySearchMember', 'SwitchTab', 'removeFn', 'onClickPopup', 'onClickPopupRadioMixed', 'selectedSingleMember', 'clearMixedMebmer', 'clearApplyMebmer', 'clearMixedMebmerRadio', 'fuzzySearchMemberMixedRadio'])
//混选成员
const mixMember = ref([])
const SwitchTab = type=> {
	emit('SwitchTab', type)
}
const fuzzySearch = (type, data)=> {
	emit('fuzzySearchMemberMixedRadio', type, data)
}
const selectLetters = (type, data)=> {
	emit('fuzzySearchMemberMixedRadio', type, data)
}
const clearMixedMebmer = ()=> {
	mixMember.value = []
	emit('clearMixedMebmerRadio')
}
const removeFn = value=> {
	mixMember.value = []
	emit('removeFn', value)
}

//选择成员-单选-复选
//子组件触发函数
const memberValue = ref('')
const radioRow = ref({})
const radioTextArea = ref('')
const radioChange = (row)=> {
	if (isRead.value) return
	radioTextArea.value = ''
	radioRow.value = row
	row.callback(row)
}
const fuzzySearchMember = (data)=> {
	emit('fuzzySearchMember', { text: data.text, letters: data.letters })
}
const selectedSingleMember = (data)=> {
	memberValue.value = data.name
	emit('selectedSingleMember', {
		data,
		radioRow: radioRow.value
	})
}
const clearApplyMebmer = ()=> {
	memberValue.value = ''
	emit('clearApplyMebmer')
}
const selectLettersSingle = (data)=> {
	emit('fuzzySearchMember', { text: data.text, letters: data.letters })
}
const onClickPopup = ()=> {
	emit('onClickPopup')
}
const onClickPopupRadioMixed = ()=> {
	emit('onClickPopupRadioMixed')
}
const selectedMember = (value)=> {
	mixMember.value = [...value.data]
	emit('selectedMemberMixedRadio', {
		data: mixMember.value,
		radioRow: radioRow.value
	})
}
// mounted
onMounted(() => {
})

</script>
<style scoped lang="scss"></style>